using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


namespace ACM.cmsarea08.Controls {
	public class CustomButton : LinkButton {
		public string ButtonName {
			get { 
				if(ViewState["CustomButton_Name" + this.ClientID]==null)
					return string.Empty;
				else
					return ViewState["CustomButton_Name" + this.ClientID].ToString();
				}
			set {
				ViewState["CustomButton_Name" + this.ClientID] = value;
			}
		}
		public CustomButton(string buttonname,string text):base() {
			this.ButtonName = buttonname;
			this.Text = text;
		}
		public CustomButton(string buttonname,string text,string css):base() {
			this.ButtonName = buttonname;
			this.Text = text;
			this.CssClass= css;
		}
		public CustomButton(string buttonname,string text,string css,EventHandler evento):base() {
			this.ButtonName = buttonname;
			this.Text = text;
			this.CssClass= css;
			this.Click+= evento;
		}		

	}

	public class CustomHref : Itan_BaseComponent {
        private string _bname;
        private string _innerhtml;
        private string _title;
        private string _href;
        private string _class;

        public string Class
        {
            get
            {
                if (ViewState["Class" + this.ID] == null)
                    return _class;
                else
                {
                    ViewState["Class" + this.ID] = _class;
                    _class = ViewState["Class" + this.ID].ToString();
                }
                return _class;
            }
            set
            {
                ViewState["Class" + this.ID] = value;
                _class = value;
            }
        }
		public string ButtonName {
			get {
                if (ViewState["CustomButton_Name" + this.ID] == null)
                    return _bname;
                else
                {
                    ViewState["CustomButton_Name" + this.ID] = _bname; 
                    _bname = ViewState["CustomButton_Name" + this.ID].ToString();
                }
                return _bname;
            }
			set {
                ViewState["CustomButton_Name" + this.ID] = value;
                _bname = value;
			}
		}
        public string InnerHtml
        {
            get
            {
                if (ViewState["InnerHtml" + this.ID] == null)
                    return _innerhtml;
                else
                {
                    ViewState["InnerHtml" + this.ID] = _innerhtml;
                    _innerhtml = ViewState["InnerHtml" + this.ID].ToString();
                }
                return _innerhtml;
            }
            set
            {
               ViewState["InnerHtml" + this.ID] = value;
                _innerhtml = value;
            }
        }
        public string Title
        {
            get
            {
                if (ViewState["Title" + this.ID] == null)
                    return _title;
                else {
                    ViewState["Title" + this.ID] = _title;
                    _title = ViewState["Title" + this.ID].ToString();
                }
                return _title;
            }
            set
            {
                 _title = value;
                 ViewState["Title" + this.ID] = value;
            }
        }
        public string HRef
        {
            get
            {
                if (ViewState["HRef" + this.ID] == null)
                    return _href;
                else
                {
                    ViewState["HRef" + this.ID] = _href;
                    _href = ViewState["HRef" + this.ID].ToString();
                }
              
                return _href;
            }
            set
            {
                _href = value;
                ViewState["HRef" + this.ID] = value;
            }
        }
		public CustomHref(string buttonname,string innerhtml):base() {
            //this.ID = buttonname;
            _title = "";
            _href = "";
            _innerhtml = "";
            _class = "";
            _bname = "";
			this.ButtonName = buttonname;
			this.InnerHtml = innerhtml;
		}
		public CustomHref(string buttonname,string innerhtml,string title):base() {
            this.ID = buttonname;
            _title = "";
            _href = "";
            _innerhtml = "";
            _bname = "";
            _class = "";
			this.ButtonName = buttonname;
			this.InnerHtml = innerhtml;
			this.Title= title;
		}
		public CustomHref(string buttonname,string innerhtml,string title,string css):base() {
            this.ID = buttonname;
            _title = "";
            _href = "";
            _innerhtml = "";
            _bname = "";
            _class = "";
			this.ButtonName = buttonname;
			this.InnerHtml = innerhtml;
			this.Title= title;
			this.Attributes.Add("class",css);
		}
		public CustomHref(string buttonname,string innerhtml,string title,string css,string href):base() {
            this.ID = buttonname;
            _title = "";
            _href = "";
            _innerhtml = "";
            _bname = "";
            _class = "";
			this.ButtonName = buttonname;
			this.InnerHtml = innerhtml;
			this.Title= title;
			if(css!="")
				this.Attributes.Add("class",css);
			this.HRef = href;
		}
		public CustomHref(string buttonname,string innerhtml,string title,string css,string href,string rel):base() {
            this.ID = buttonname;
            _title      = "";
            _href       = "";
            _innerhtml  = "";
            _bname      = "";
            _class = "";
			this.ButtonName = buttonname;
			this.InnerHtml  = innerhtml;
			this.Title      = title;
			if(css!="")
				this.Attributes.Add("class",css);
			this.HRef = href;
			if(rel!="")
				this.Attributes.Add("rel",rel);
		}

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            //Response.Write("SONO IO: " + this.InnerHtml + ", " + this.Title + ", " + this.ButtonName + ", " + this.InstanceID);
        }
        protected override void Render(HtmlTextWriter writer)
        {
            //writer.Write("SONO QUI");
            if (this.Visible == false) return;
            //base.Render(writer);
            string mioah = "";
            mioah = (this.HRef.Length>0?" href=\"" + this.HRef + "\" ":"");
            mioah += (this.Title.Length>0?" title=\"" + this.Title + "\" ":"");
            mioah += (this.Class.Length > 0 ? " class=\"" + this.Class + "\" " : "");


            writer.Write("<a "+mioah+" ");
            this.Attributes.Render(writer);
            writer.Write(">" + this.InnerHtml + "</a>");
        }
    }


}
